package com.zjw.zy.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;
import com.zjw.zy.utils.TimeUtils;

/**
 * @author ：zhong.jw
 * @date ：Created in 2022/10/12 9:30
 */
public class HourlyWeather implements Parcelable {

    //天气现象
    @SerializedName("text")
    public String text;
    //现象代码
    @SerializedName("code")
    public String code;
    //气温 ℃
    @SerializedName("temp_fc")
    public int tempFc;
    //风级
    @SerializedName("wind_class")
    public String windClass;
    //风速 m/s
    @SerializedName("wind_speed")
    public float windSpeed;
    //风向 西北风
    @SerializedName("wind_dir")
    public String windDir;
    //风向角度 0正北风
    @SerializedName("wind_angle")
    public String windAngle;
    //相对湿度 %
    @SerializedName("rh")
    public int rh;
    //降雨量 mm
    @SerializedName("prec")
    public float prec;
    //气压 hPa
    @SerializedName("pressure")
    public int pressure;
    //云量
    @SerializedName("clouds")
    public int clouds;
    //体感温度
    @SerializedName("feels_like")
    public int feelsLike;
    //预报当地时间
    @SerializedName("data_time")
    public String dateTime;

    public HourlyWeather() {

    }

    protected HourlyWeather(Parcel in) {
        text = in.readString();
        code = in.readString();
        tempFc = in.readInt();
        windClass = in.readString();
        windSpeed = in.readFloat();
        windDir = in.readString();
        windAngle = in.readString();
        rh = in.readInt();
        prec = in.readFloat();
        pressure = in.readInt();
        clouds = in.readInt();
        feelsLike = in.readInt();
        dateTime = in.readString();
    }

    public static final Creator<HourlyWeather> CREATOR = new Creator<HourlyWeather>() {
        @Override
        public HourlyWeather createFromParcel(Parcel in) {
            return new HourlyWeather(in);
        }

        @Override
        public HourlyWeather[] newArray(int size) {
            return new HourlyWeather[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(text);
        dest.writeString(code);
        dest.writeInt(tempFc);
        dest.writeString(windClass);
        dest.writeFloat(windSpeed);
        dest.writeString(windDir);
        dest.writeString(windAngle);
        dest.writeInt(rh);
        dest.writeFloat(prec);
        dest.writeInt(pressure);
        dest.writeInt(clouds);
        dest.writeInt(feelsLike);
        dest.writeString(dateTime);
    }

    public String getTime() {
        int start = dateTime.lastIndexOf(" ");

        return dateTime.substring(start);
    }


    public boolean isDay() {
        String time = getTime();
        String[] split = time.split(":");
        int hour = Integer.parseInt(split[0].trim());
        int minute = Integer.parseInt(split[1].trim());

        TimeUtils.SunTimeBean sunTime = TimeUtils.getSunTime();

        return hour * 60 + minute >= sunTime.getSunRaiseHour() * 60 + sunTime.getSunRaiseMinute() &&
                hour * 60 + minute <= sunTime.getSunResetHour() * 60 + sunTime.getSunResetMinute();
    }
}
